Skip to content

Conversation

zibs
Copy link

@zibs zibs commented Jul 7, 2025

Description

I'm noticing with Fabric enabled on Android with these packages an increase in crashes on Android have begun to occur. The error is "Exception thrown when executing UIFrameGuarded"

07-07 14:23:29.069 18919 18919 E DevLauncher: Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
07-07 14:23:29.069 18919 18919 E DevLauncher: 	at android.view.ViewGroup.addViewInner(ViewGroup.java:5256)
07-07 14:23:29.069 18919 18919 E DevLauncher: 	at android.view.ViewGroup.addView(ViewGroup.java:5085)
07-07 14:23:29.069 18919 18919 E DevLauncher: 	at android.view.ViewGroup.addView(ViewGroup.java:5025)
07-07 14:23:29.069 18919 18919 E DevLauncher: 	at android.view.ViewGroup.addView(ViewGroup.java:4997)
07-07 14:23:29.069 18919 18919 E DevLauncher: 	at com.swmansion.rnscreens.ScreenStackHeaderConfig.onUpdate(ScreenStackHeaderConfig.kt:339)
07-07 14:23:29.069 18919 18919 E DevLauncher: 	at com.swmansion.rnscreens.ScreenStackHeaderConfig.onAttachedToWindow(ScreenStackHeaderConfig.kt:156)

package.json:

"expo": "^53.0.18",
"react-native": "0.79.5",
"react-native-screens": "~4.11.1",
"@react-navigation/bottom-tabs": "^6.5.8",
"@react-navigation/native": "^6.1.7",
"@react-navigation/native-stack": "^6.9.13",

Potentially fixes #2941 (and others)

I don't know if this "fix" is actually what you'd want or not, but maybe it'll give you guys an idea of somewhere to take a closer look?

The crash seems to be most reproducible when logging out and the navigation structure is changing:

<RootStack.Navigator>
{isLoggedIn ? <LoggedInStack Etc/> : <LoggedOutStack /> }
</RootStack.Navigator>

I don't think this PR is really mergeable as is but maybe it'll lay the groundwork for something that is/future fixes?

@zibs zibs changed the title fix: removeView on update if needed fix(Android): removeView on update if needed Jul 7, 2025
@kkafar
Copy link
Member

kkafar commented Aug 4, 2025

Sorry for late response. Do you have any additional context of how we can reproduce the issue? I've tried this simple setup & it seems to work fine on my end unfortunately.

@soutua
Copy link

soutua commented Aug 18, 2025

We've also started seeing similar crashes in our app, after we switched on the new architecture:

          Fatal Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5264)
       at android.view.ViewGroup.addView(ViewGroup.java:5093)
       at android.view.ViewGroup.addView(ViewGroup.java:5030)
       at android.view.ViewGroup.addView(ViewGroup.java:5002)
       at com.swmansion.rnscreens.ScreenStackHeaderConfig.onUpdate(ScreenStackHeaderConfig.kt:339)
       at com.swmansion.rnscreens.ScreenStackHeaderConfig.onAttachedToWindow(ScreenStackHeaderConfig.kt:156)
       at android.view.View.dispatchAttachedToWindow(View.java:21092)
       at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3501)
       at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3508)
       at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3508)
       at android.view.ViewGroup.addViewInner(ViewGroup.java:5307)
       at android.view.ViewGroup.addView(ViewGroup.java:5093)
       at android.view.ViewGroup.addView(ViewGroup.java:5030)
       at androidx.fragment.app.FragmentStateManager.addViewToContainer(FragmentStateManager.java:881)
       at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:565)
       at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
       at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
       at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
       at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1751)
       at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323)
       at com.swmansion.rnscreens.ScreenStack.onUpdate(ScreenStack.kt:267)
       at com.swmansion.rnscreens.ScreenContainer.performUpdates(ScreenContainer.kt:367)
       at com.swmansion.rnscreens.ScreenContainer.onScreenChanged$lambda$8(ScreenContainer.kt:350)

Don't know of reproduction since we've only seen this on our crash logs.

@kkafar
Copy link
Member

kkafar commented Aug 30, 2025

@soutua does the situation improve if you apply patch from this PR?

I'm very reluctant to land this one, since I've no idea what causes the crash.

@zibs
Copy link
Author

zibs commented Aug 30, 2025

I will I say I think the app that was using this was potentially misusing suspense in the app, and after getting rid of it/using it properly it seemed to be fine.

So this pr may not be relevant!

@soutua
Copy link

soutua commented Aug 30, 2025

@soutua does the situation improve if you apply patch from this PR?

I'm unable to try it at this time, since I would need to try it on the production version but we moved back into using the react native's old architecture due to other issues with the new arch, so it's no longer crashing.

On zibs' Suspense comment; we are not using Suspense in our app and it was still having crashes. But of course it could have something to so with asynchronous code being run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested Navigation and Logout function issue

3 participants